#pragma once
#include "graphics.h"

#include <time.h>

#include <Mmsystem.h>

class cSprite9
{
private:
	float mX;
	float mY;
	float mZ;

	int mWidth;
	int mHeight;

	// for scaling lol
	float mScaleX;
	float mScaleY;

	// for animation
	int mFrames; // 0 for not loaded
	int mFramesX;
	int mFramesY;
	int mCurrentFrame;
	int mColumns;
	int mRows;

	// Source rect
	RECT mRect[12]; // instead of computing them every frame

	RECT mWindow; // For position ( Dest rect )

	D3DXIMAGE_INFO mInfo; // For reset purposes


	// For drawing
	D3DXMATRIX mOriginalMatrix;
	D3DXMATRIX mFrameMatrix;

	D3DXMATRIX mTemp;

	D3DXVECTOR2 mTranslation; // Screen coords

	// For whole file
	D3DXVECTOR3 mCenter;    // center at the upper-left corner
	// For sprite
	D3DXVECTOR2 mSpriteCenter; // Width and height / 2

	// For scaling
	D3DXVECTOR2 mScaling; // default to 2.5
	D3DXVECTOR3 mPosition;    // position at x and y at lowest level

	string mFile; // for debugging purposes

	LPDIRECT3DTEXTURE9 p_mFile; // whole image file

public:
	cSprite9();
	~cSprite9();

	LPDIRECT3DTEXTURE9 getTexture(int iFrame = 0) const {return p_mFile;}

	bool getSprite() const { if ( mFrames == 1 ) return false; else return true; }

	void setZ(float iZ);

    int getCurrentFrame() const { return mCurrentFrame; }

    inline void incCurrentFrame() {
        mCurrentFrame++;
        if(mCurrentFrame==mFrames)
            mCurrentFrame = 0;
            }

	float getX() const { return mX; }
	float getY() const { return mY; }
	float getZ() const { return mZ; }

	float getScaleX() const { return mScaleX; }
	float getScaleY() const { return mScaleY; }

	void load(LPDIRECT3DDEVICE9 pDevice, string sFile); // for display whole surfaces
	void load(LPDIRECT3DDEVICE9 pDevice, string sFile, int iWidth, int iHeight); // for animation

	void draw(LPDIRECT3DDEVICE9 pDevice, LPD3DXSPRITE pSprite); // determines by number of frames
	void moveTo(float iX, float iY); // moves to specific location without limits
	void moveX(float iX); // moves within limits
	void moveY(float iY); // moves within limits

	void setScale( float scaleX, float scaleY );
};
